package featuresdemo;

/**
 * Created by pc on 2015/2/2.
 * 基本类型自动转换测试* 
 */
public class AutoConversion {
    public static void main(String[] args) {
        //long是8字节，float是4字节
        long a = 6L;
        float b = a;
        System.out.println(b);
//        System.out.println(Integer.MAX_VALUE-(-Integer.MAX_VALUE)); //内存溢出
        System.out.println(Integer.MAX_VALUE); //2的31次方-1,10个数位，正的20亿左右,用在钱上面不一定够
        System.out.println(Integer.MIN_VALUE); //负的2的31次方
        System.out.println(Long.MAX_VALUE); //2的64次方-1,19个数位，很大了,可放心用在钱上面
        System.out.println(Long.MIN_VALUE); //负的2的64次方
        System.out.println(Float.MAX_VALUE); //2的128次方-1,38个数位，比long多了一倍,这个主要用来做简单数学精确运算使用
        System.out.println(Float.MIN_VALUE); //2的-149次方
        System.out.println(Double.MAX_VALUE); //2的1024次方-1,308个数位，是float数位的10倍，主要用来做复杂运算和天文运算
        System.out.println(Double.MIN_VALUE); //2的-1074次方
        //char 是32767
        char cc = '你';
        System.out.println((byte) cc);
        System.out.println((short) cc);
        System.out.println((int) cc);
        int ii = 23456;
        System.out.println((char) ii);
        char testChar = (char) 70000;
        int real = (char) 70000;
        System.out.println("real:" + real);
        char testChar2 = (char) 280388456;
        System.out.println(testChar);
        System.out.println(testChar2);
        System.out.println((Character.MIN_VALUE + 0) + "<char<" + (Character.MAX_VALUE + 0));

        //String加法
        System.out.println("Hello" + 'd' + 8);
        System.out.println('g' + 7 + "Hello");
        
        //double的直接量，还有就是 后面加D, 或直接浮点
        System.out.println(3.14E2);
        
        //overflow
        System.out.println("(byte) 129: " + (byte) 129);
        System.out.println("(byte)  1000l: " + (byte) 1000l);
        System.out.println("(byte)  100: " + (byte) 100);

        String longStr = "我们是害虫吗？对啊.";
        char [] longChar = longStr.toCharArray();
        for (char aLongChar : longChar) {
            System.out.println(aLongChar + ":" + (int) aLongChar);
        }
        
        //only works for -128 ~ 127, because of integer cache for auto boxing
        Integer a1 = 3;
        Integer a2 = 3;
        System.out.println(a1 == a2);  // smaller than 128
        Integer a3 = 333;
        Integer a4 = 333;
        System.out.println(a3 == a4); // reference checking, not same address
        System.out.println(333 == 333);  //not reference checking

        //
        float fa = 65.00f;
        System.out.println( "65 == 65.00f ? " + (65 == fa));
        System.out.println( 65 == fa);
    }
}
